package com.clound.order.message;

import com.clound.order.utils.JsonUtil;
import com.clound.product.common.ProductInfoOutput;
import com.fasterxml.jackson.core.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by zzy on 2018/4/12.
 */
@Component
public class ProductInfoReveiver {

    private final static Logger log= LoggerFactory.getLogger(ProductInfoReveiver.class);

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queuesToDeclare = @Queue("productInfo"))
    public void process(String message){
        List<ProductInfoOutput> productInfoOutputs= JsonUtil.jsonToObj(message,
                new TypeReference<List<ProductInfoOutput>>() {});
        log.info("从队列【{}】 接收到消息{}","productInfo",productInfoOutputs);

        //todo 存入redis
    }
}
